package com.tedu.service;

import com.tedu.feign.ItemClient;
import com.tedu.feign.UserClient;
import com.tedu.pojo.Item;
import com.tedu.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/23
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService{

    @Autowired
    ItemClient itemClient;

    @Autowired
    UserClient userClient;

    @Override
    public Order getOrder(String orderId) {
        //TODO: 调用user-service获取用户信息

        //TODO: 调用item-service获取商品信息
        Order order = new Order();
        order.setUser(userClient.getUser(8).getData());
        order.setItems( itemClient.getItems(orderId).getData());
        order.setId(orderId);
        return order;
    }

    @Override
    public void addOrder(Order order) {
        //TODO: 调用item-service减少商品库存
        //TODO: 调用user-service增加用户积分
        userClient.addScore(order.getUser().getId(),1);
        itemClient.decreaseNumber(order.getItems());
        log.info("保存订单："+order);
    }
}
